Description:
ANR detects cases where evaluation of a field reference expression will result in
a
System.NullReferenceException being thrown.
ANR is reported whenever a
non-static field of an object or array is accessed and the left operand
of the . (field access) operator has the
null value.
Incorrect:
public void PrintMessage(Message msg) {
if (msg != null) {
msg.Print();
} else {
Console.WriteLine(msg.ToString() + " is null");
}
}
Correct:
public void PrintMessage(Message msg) {
if (msg != null) {
msg.Print();
} else {
Console.WriteLine("msg is null");
}
}